A good answer might be:

Compile and run the program. It is not complete, but it should run correctly with the first half of the data. Always compile and run a program-in-progress as soon as you can. Catch design flaws and bugs as early as you can.

Last Half

The last half of the program is nearly the same as the first, so it is a good idea to check that the first half works before going on. Here is the completed program:

import java.io.*;
class TestGroups
{
  public static void main ( String[] args ) throws IOException
  {
    String line;
    BufferedReader stdin = new BufferedReader( 
        new InputStreamReader( System.in ) );
    int value;     // the value of the current integer

    // Group "A"
    int sizeA;     // the number of students in group "A"
    int sumA = 0;  // the sum of scores for group "A"

    System.out.println("How many students in group A:");
    line   = stdin.readLine();
    sizeA  = Integer.parseInt( line.trim() );

    int count = 0; // initialize count

    while ( count < sizeA )
    {
      System.out.println("Enter a number:");
      line   = stdin.readLine();
      value  = Integer.parseInt( line.trim() );
      sumA  = sumA + value ; // add to the sum
      count = count + 1;     // increment the count
    }

    if ( sizeA > 0 )
      System.out.println( "Group A average: " + ((double) sumA)/sizeA );
    else
      System.out.println( "Group A  has no students" );
  
    // Group "B"
    int sizeB;     // the number of students in group "B"
    int sumB = 0;   // the sum of scores for group "B"

    System.out.println("How many students in group B:");
    line   = stdin.readLine();
    sizeB  = Integer.parseInt( line.trim() );

    count = 0; // initialize count

    while ( count < sizeB )
    {
      System.out.println("Enter a number:");
      line   = stdin.readLine();
      value  = Integer.parseInt( line.trim() );
      sumB  = sumB + value ; // add to the sum
      count = count + 1; // increment the count
    }

    if ( sizeB > 0 )
      System.out.println( "Group B average: " + ((double) sumB)/sizeB );
    else
      System.out.println( "Group B  has no students" );
  }
}

The two halves of the code are very similar.

QUESTION 11:

Is it a mistake to declare the variables sizeB and sumB in the middle of the program?